package com.java.string.StringBuilder.source_analyze.source_code;

public class StringBuilder extends AbstractStringBuilder {
    // ①默认初始容量为16，构造函数指定容量时则为指定容量，构造函数指定字符串时则为(16+字符串长度)
    public StringBuilder() {
        // 默认初始容量为16
        super(16);
    }
    
    public StringBuilder(int capacity) {
        // 构造函数指定容量时则为指定容量
        super(capacity);
    }
    
    public StringBuilder(String str) {
        // 构造函数指定字符串时则为`16+字符串长度`
        super(str.length() + 16);
        
        // 向StringBuilder容器中添加字符串
        append(str);
    }
    
    @Override
    public StringBuilder append(String str) {
        super.append(str);
        return this;
    }
    
    @Override
    public String toString() {
        return new String(value, 0, count);
    }
}
